package com.wlc.oop.demo08;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 英雄
 * @date 2021-07-03 10:08
 */
public class Hero {
    String name;
    float hp =30;
    /**
     * 英雄只需要传入相应的不同
     * 属性的类即可
     *
     * @param item
     */
    public void userItem(Item item, String name) {
        item.effect(name);
    }

    public Hero() {
        //System.out.println("父类无参数构造方法");
    }

    public Hero(String name) {
        System.out.println("父类带参数构造方法 " + name);
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    public void finalize() {
        System.out.println("这个英雄正在被回收");
    }

    /**
     * 当下一个对象创建好以后，上一个对象的引用指向新的对象
     */
    public void method01() {
        Hero h;
        for (int i = 0; i < 100000; i++) {
            System.out.println(i);
            h = new Hero();
        }
    }

    public void method02() {
        Hero hero1 = new Hero();
        Hero hero2 = new Hero();
        Hero hero3 = new Hero();
        System.out.println(hero1 == hero2);
        System.out.println(hero1 == hero3);
    }

    public boolean equal(Object o) {
        if (o instanceof Hero) {
            Hero hero = (Hero) o;
            return this.hp == hero.hp;
        }
        return false;
    }
    public void method03(){
        System.out.println(super.getClass());
    }

    public static void main(String[] args) {
        Hero hero1 = new Hero();
        hero1.hp = 301;
        System.out.println(new Hero().equal(hero1));
        new Hero().method03();
        final Hero hero2;
        hero2 = new Hero();

    }
}
